package calendar;

import java.text.SimpleDateFormat;
import java.util.Calendar;

/**
 * @Description: 作用描述
 * @Author: hmm
 * @CreateDate: 2019/7/25$ 11:13$
 * @UpdateUser: hmm
 * @UpdateDate: 2019/7/25$ 11:13$
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
public class DateUtil {
    /**
     * 获取当前周周一日期
     *
     * @return
     */
    public static String getWeekBegin() {
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        calendar.setFirstDayOfWeek(Calendar.MONDAY);
        int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
        calendar.add(Calendar.DATE, calendar.getFirstDayOfWeek() - dayOfWeek);
        return sdf.format(calendar.getTime());
    }

    /**
     * 获取当前周周日日期
     *
     * @return
     */
    public static String getWeekEnd() {
        Calendar calendar = Calendar.getInstance();
        int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK) - 1;
        if (dayOfWeek == 0) {
            dayOfWeek = 7;
        }
        calendar.add(Calendar.DATE, -dayOfWeek + 7);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.format(calendar.getTime());
    }

    /**
     * 获取当前周
     *
     * @return
     */
    public static int getWeekOfYear() {
        Calendar calendar = Calendar.getInstance();
        return calendar.get(Calendar.WEEK_OF_YEAR);
    }

}
